<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="API docs for the StreamController.broadcast constructor from the Class StreamController class from the dart:async library, for the Dart programming language.">
  <title>StreamController.broadcast constructor - StreamController class - dart:async library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="../..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">

</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">spritewidget</a></li>
    <li><a href="dart-async/dart-async-library.html">dart:async</a></li>
    <li><a href="dart-async/StreamController-class.html">StreamController<span class="signature">&lt;<wbr><span class="type-parameter">T</span>&gt;</span></a></li>
    <li class="self-crumb">StreamController.broadcast factory constructor</li>
  </ol>
  <div class="self-name">StreamController.broadcast</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <h5>StreamController class</h5>
    <ol>
      <li class="section-title"><a href="dart-async/StreamController-class.html#constructors">Constructors</a></li>
      <li><a href="dart-async/StreamController/StreamController.html">StreamController</a></li>
      <li><a href="dart-async/StreamController/StreamController.broadcast.html">broadcast</a></li>
    
      <li class="section-title">
        <a href="dart-async/StreamController-class.html#instance-properties">Properties</a>
      </li>
      <li><a href="dart-async/StreamController/hasListener.html">hasListener</a></li>
      <li><a href="dart-async/StreamController/isClosed.html">isClosed</a></li>
      <li><a href="dart-async/StreamController/isPaused.html">isPaused</a></li>
      <li><a href="dart-async/StreamController/onCancel.html">onCancel</a></li>
      <li><a href="dart-async/StreamController/onListen.html">onListen</a></li>
      <li><a href="dart-async/StreamController/onPause.html">onPause</a></li>
      <li><a href="dart-async/StreamController/onResume.html">onResume</a></li>
      <li><a href="dart-async/StreamController/sink.html">sink</a></li>
      <li><a href="dart-async/StreamController/stream.html">stream</a></li>
      <li class="inherited"><a href="dart-async/StreamSink/done.html">done</a></li>
      <li class="inherited"><a href="dart-core/Object/hashCode.html">hashCode</a></li>
      <li class="inherited"><a href="dart-core/Object/runtimeType.html">runtimeType</a></li>
    
      <li class="section-title"><a href="dart-async/StreamController-class.html#instance-methods">Methods</a></li>
      <li><a href="dart-async/StreamController/add.html">add</a></li>
      <li><a href="dart-async/StreamController/addError.html">addError</a></li>
      <li><a href="dart-async/StreamController/addStream.html">addStream</a></li>
      <li><a href="dart-async/StreamController/close.html">close</a></li>
      <li class="inherited"><a href="dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
      <li class="inherited"><a href="dart-core/Object/toString.html">toString</a></li>
    
      <li class="section-title inherited"><a href="dart-async/StreamController-class.html#operators">Operators</a></li>
      <li class="inherited"><a href="dart-core/Object/operator_equals.html">operator ==</a></li>
    
    
    
    </ol>
  </div><!--/.sidebar-offcanvas-left-->

  <div class="col-xs-12 col-sm-9 col-md-8 main-content">
    <h1>StreamController&lt;<wbr><span class="type-parameter">T</span>&gt;.broadcast constructor</h1>

    <section class="multi-line-signature">
      
      <span class="name ">StreamController&lt;<wbr><span class="type-parameter">T</span>&gt;.broadcast</span>(<wbr>{<span class="parameter" id="broadcast-param-onListen"><span class="type-annotation">void</span> <span class="parameter-name">onListen</span>(), </span> <span class="parameter" id="broadcast-param-onCancel"><span class="type-annotation">void</span> <span class="parameter-name">onCancel</span>(), </span> <span class="parameter" id="broadcast-param-sync"><span class="type-annotation"><a href="dart-core/bool-class.html">bool</a></span> <span class="parameter-name">sync</span>: <span class="default-value">false</span></span> })
    </section>

    <section class="desc markdown">
      <p>A controller where <a href="dart-async/StreamController/stream.html">stream</a> can be listened to more than once.</p>
<p>The <a href="dart-async/Stream-class.html">Stream</a> returned by <a href="dart-async/StreamController/stream.html">stream</a> is a broadcast stream.
It can be listened to more than once.</p>
<p>A Stream should be inert until a subscriber starts listening on it (using
the <code>onListen</code> callback to start producing events). Streams should not
leak resources (like websockets) when no user ever listens on the stream.</p>
<p>Broadcast streams do not buffer events when there is no listener.</p>
<p>The controller distributes any events to all currently subscribed
listeners at the time when <a href="dart-async/StreamController/add.html">add</a>, <a href="dart-async/StreamController/addError.html">addError</a> or <a href="dart-async/StreamController/close.html">close</a> is called.
It is not allowed to call <code>add</code>, <code>addError</code>, or <code>close</code> before a previous
call has returned. The controller does not have any internal queue of
events, and if there are no listeners at the time the event is added,
it will just be dropped, or, if it is an error, be reported as uncaught.</p>
<p>Each listener subscription is handled independently,
and if one pauses, only the pausing listener is affected.
A paused listener will buffer events internally until unpaused or canceled.</p>
<p>If <code>sync</code> is true, events may be fired directly by the stream's
subscriptions during an <a href="dart-async/StreamController/add.html">add</a>, <a href="dart-async/StreamController/addError.html">addError</a> or <a href="dart-async/StreamController/close.html">close</a> call.
The returned stream controller is a <a href="dart-async/SynchronousStreamController-class.html">SynchronousStreamController</a>,
and must be used with the care and attention necessary to not break
the <a href="dart-async/Stream-class.html">Stream</a> contract.
See <a href="dart-async/Completer/Completer.sync.html">Completer.sync</a> for some explanations on when a synchronous
dispatching can be used.
If in doubt, keep the controller non-sync.</p>
<p>If <code>sync</code> is false, the event will always be fired at a later time,
after the code adding the event has completed.
In that case, no guarantees are given with regard to when
multiple listeners get the events, except that each listener will get
all events in the correct order. Each subscription handles the events
individually.
If two events are sent on an async controller with two listeners,
one of the listeners may get both events
before the other listener gets any.
A listener must be subscribed both when the event is initiated
(that is, when <a href="dart-async/StreamController/add.html">add</a> is called)
and when the event is later delivered,
in order to receive the event.</p>
<p>The <code>onListen</code> callback is called when the first listener is subscribed,
and the <code>onCancel</code> is called when there are no longer any active listeners.
If a listener is added again later, after the <code>onCancel</code> was called,
the <code>onListen</code> will be called again.</p>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span> </h2>
      <pre class="language-dart"><code class="language-dart">factory StreamController.broadcast(
    {void onListen(), void onCancel(), bool sync: false}) {
  return sync
      ? new _SyncBroadcastStreamController&lt;T&gt;(onListen, onCancel)
      : new _AsyncBroadcastStreamController&lt;T&gt;(onListen, onCancel);
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    spritewidget 0.9.16
  </span>

</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
